//
//  LoginWithPadControl.m
//  ai2ban
//
//  Created by Heartbeats on 2018/1/14.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "LoginWithPadControl.h"
#import "FindPsdControl.h"
#import "NetworkManager.h"

@interface LoginWithPadControl ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *psdTextFile;
@property (weak, nonatomic) IBOutlet UIButton *registBtn;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end

@implementation LoginWithPadControl

- (void)viewDidLoad {
    [super viewDidLoad];
    self.phoneText.text = @"18321655626";
    self.psdTextFile.text = @"123456";
    self.registBtn.clipsToBounds = true;
    self.registBtn.layer.cornerRadius = 8;
    self.registBtn.layer.borderColor = [kWhiteColor CGColor];
    self.registBtn.layer.borderWidth = 1;
    
    self.loginBtn.clipsToBounds = true;
    self.loginBtn.layer.cornerRadius = 10;
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController.navigationBar setHidden:true];
}

- (IBAction)doBack:(UIButton *)sender {
    [self dismissViewControllerAnimated:true completion:nil];
}

- (IBAction)registAction:(UIButton *)sender {
    LoginViewViewController *regViewC = [[LoginViewViewController alloc] initWithNibName:@"LoginViewViewController" bundle:nil];
    
    [self.navigationController pushViewController:regViewC animated:true];
}

- (IBAction)forgetPasAction:(UIButton *)sender {
    FindPsdControl *finpsdCon = [[FindPsdControl alloc]initWithNibName:@"FindPsdControl" bundle:nil];
    [self.navigationController pushViewController:finpsdCon animated:true];
}

- (IBAction)loginAction:(UIButton *)sender {
    [ActivityIndicatorView show];
    NSDictionary *param = @{@"loginName": self.phoneText.text, @"loginPassword": self.psdTextFile.text};
    [[NetworkManager shareNetwork] requestWithURLString:@"/morning/app/system/login" parameters:param method:@"POST" callBack:^(id responseObject) {
        [ActivityIndicatorView dismiss];
        if ([responseObject[@"state"] intValue]) {
            [AppManager loginWithUserID:responseObject[@"data"] psd:self.psdTextFile.text];
            AppManager.isLogin = true;
            [[NSNotificationCenter defaultCenter] postNotificationName:UpdateUserDataNotification object:nil];
            [self dismissViewControllerAnimated:true completion:nil];
            return;
        }
        [MozTopAlertView showWithType:MozAlertTypeError text:@"登录失败" parentView:self.view];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
